import { defineStore } from 'pinia'

export const useMenuStore = defineStore('menu', {
  state: () => ({
    menus: [],
    collapsed: false,
    theme: 'light'
  }),

  actions: {
    // 获取菜单数据
    async fetchMenus() {
      // 模拟API调用
      await new Promise(resolve => setTimeout(resolve, 500))
      
      this.menus = [
        {
          path: '/',
          name: 'Home',
          meta: { title: '首页', icon: 'HomeFilled' }
        },
        {
          path: '/customer',
          name: 'CustomerManagement',
          meta: { title: '客户管理', icon: 'User' }
        },
        {
          path: '/system',
          name: 'System',
          meta: { title: '系统管理', icon: 'Setting' },
          children: [
            {
              path: '/system/user',
              name: 'UserManagement',
              meta: { title: '用户管理', icon: 'User' }
            },
            {
              path: '/system/role',
              name: 'RoleManagement',
              meta: { title: '角色管理', icon: 'Avatar' }
            }
          ]
        }
      ]
    },

    // 切换菜单折叠状态
    toggleCollapsed() {
      this.collapsed = !this.collapsed
    },

    // 切换主题
    toggleTheme() {
      this.theme = this.theme === 'light' ? 'dark' : 'light'
    }
  }
})